function init(){
	getDefects();
}

function getDefects(){

	var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__', 
															'__PROJECT_OID__',  
															'__PROJECT_SCOPING_UP__', 
															'__PROJECT_SCOPING_DOWN__');													
	var queryConfig = [];
	queryConfig[0] = {  
                key: 'out',  
                type: 'Defect',
                fetch: 'FormattedID,Name,Requirement,Severity,Priority,State,Iteration,Release,Resolution,TestCase'
            };
	rallyDataSource.findAll(queryConfig, function(results){
		processDefects(results);
	});
}

function processDefects(results){
	console.log(results);
	var csv = _.reduce(results.out, function(memo,val){
														memo += val.FormattedID + ",\"" + val.Name.replace(/"/g, "'") + "\"," + (val.Requirement ? val.Requirement.FormattedID : "") + "," + val.Severity + "," + val.Priority + "," + val.State	+ "," + (val.Iteration? val.Iteration.Name : "") + "," + (val.Release? val.Release.Name : "") + "," + val.Resolution + "," + (val.TestCase ? val.TestCase.FormattedID : "") + "<br/>";
														return memo;
													}, "");
	$j("#cntnt").html(csv);
}